package com.javajun.endofterm.entity;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.javajun.endofterm.common.CommonEntity;
import org.hibernate.annotations.NotFound;
import org.hibernate.annotations.NotFoundAction;

import javax.persistence.*;
import java.util.Date;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * Author: Xiong Limin
 * Date: 2020-12-02-1:21 下午
 */
@Entity
public class PowerRecord extends CommonEntity<Integer> {
    private Date updateTime;
    private Double usePower;
    private String opera;

    @ManyToOne(cascade = {CascadeType.MERGE, CascadeType.REFRESH})
    @JoinColumn
    @JsonIgnore // 不进行序列化
    @NotFound(action= NotFoundAction.IGNORE)
    private Domitory domitory;

    @Transient
    public String getDomitoryName() {
        String str = "";
        if (domitory != null) {
            str = domitory.getName();
        }
        return str;
    }

    public Date getUpdateTime() {
        return updateTime;
    }

    public void setUpdateTime(Date updateTime) {
        this.updateTime = updateTime;
    }

    public Double getUsePower() {
        return usePower;
    }

    public void setUsePower(Double usePower) {
        this.usePower = usePower;
    }

    public String getOpera() {
        return opera;
    }

    public void setOpera(String opera) {
        this.opera = opera;
    }

    public Domitory getDomitory() {
        return domitory;
    }

    public void setDomitory(Domitory domitory) {
        this.domitory = domitory;
    }

    public PowerRecord(Domitory domitory, Double usePower, String opera) {
        this.domitory = domitory;
        this.usePower = usePower;
        this.opera = opera;
        this.updateTime = new Date();
    }

    public PowerRecord() {
    }
}
